﻿@using TimerTask.Common.Utils
@model List<TimerTask.Model.Entity.GroupInfo>
@{
    ViewBag.Title = "任务列表";
    Layout = null;
}


<div class="box">
    <div class="box-header">
        <div class="row">
            <div class="col-sm-2 m-b-xs">
                <select class="input form-control input-s-sm inline" id="groupId">
                    <option value="0">请选择</option>
                    @if (Model != null && Model.Count > 0)
                    {
                        foreach (var groupInfo in Model)
                        {
                            <option value="@groupInfo.Id">@groupInfo.GroupName</option>
                        }
                    }
                </select>
            </div>
            <div class="col-sm-1">
                <div class="input-group">
                    <button type="button" id="btnSearch" class="btn btn-sm btn-primary">搜索</button>
                </div>
            </div>
            <div class="col-sm-3">
                <div class="input-group">
                    <button type="button" id="btnNew" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#newJob">新建</button>
                </div>
            </div>
        </div>

    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="dataTables_wrapper form-inline dt-bootstrap"  id="main_content">
        </div>
    </div>
    <!-- /.box-body -->
</div>

<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
            
                <div class="row">
                    <div class="table-responsive ibox-content" id="main_content">
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="newJob" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title">新建任务</h4>
                    <div class="modal-body">
                        <div class="ibox-content">
                            <form class="form-horizontal" id="frmNew">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">任务名：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="任务名" name="jobName" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">任务组：</label>
                                    <div class="col-sm-8">
                                        <select class="input form-control input-s-sm inline" name="groupId">
                                            <option value="0">请选择</option>
                                            @if (Model != null && Model.Count > 0)
                                            {
                                                foreach (var groupInfo in Model)
                                                {
                                                    <option value="@groupInfo.Id">@groupInfo.GroupName</option>
                                                }
                                            }
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">执行周期：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="执行周期" class="form-control" name="cron">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">联系人Tel：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="联系人Tel" class="form-control" name="contactTel">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">联系人Email：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="联系人Email" class="form-control" name="contactEmail">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">请求地址：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="请求地址" class="form-control" name="requestUrl">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">成功判断：</label>

                                    <div class="col-sm-8">
                                        <input type="text" placeholder="成功返回" class="form-control" name="resAssert">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal" id="btnClose">关闭</button>
                        <button type="button" class="btn btn-primary" id="btnSave">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>
        $(function () {
            loadPage(1, 0);
            $('#btnSearch').click(function () {
                loadPage(1);
            });
            $('#btnSave').click(function () {
                var postData = $('#frmNew').serialize();
                $.post('@Url.Action("NewSave")',
                    postData,
                    function (res) {
                        if (res.code === 1) {
                            $('#btnClose').click();
                            loadPage(1);
                        } else {
                            alert(res.msg);
                        }
                    });
            });
        });

        function loadPage(pageIndex) {
            var postData = {};
            postData.index = pageIndex;
            postData.groupId = $('#groupId').val();
            $.post('@Url.Action("Get", "Job")?t=' + Math.random(),
                postData,
                function (res) {
                    $('#main_content').html(res);
                });
        }
    </script>
</div>